//
//  SFPMaternityNotesModel.swift
//  StriveForPregnancy
//
//  Created by iOS-Czz on 2023/11/9.
//

import UIKit

class SFPMaternityNotesViewModel{
    var dataSource = [SFPMaternityNotesModel]()
    var totals = ""
}
extension SFPMaternityNotesViewModel{
    func getPageData(onSuccess: ((_ models: [SFPMaternityNotesModel]) ->Void)?){
        let dataHelper = SFPMaternityNotesModel.getUsingLKDBHelper()
        let sql = "select * from @t"
        let modelArr = dataHelper.search(withSQL: sql, to: SFPMaternityNotesModel.self) as! [SFPMaternityNotesModel]
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy.MM.dd"
        let sortedModels = modelArr.sorted { (model1, model2) -> Bool in
            guard let date1 = dateFormatter.date(from: model1.date),
                  let date2 = dateFormatter.date(from: model2.date) else {
                return false // 如果转换失败则直接返回 false
            }
            return date1 > date2
        }
        if sortedModels.count > 9 {
            self.totals = String(format: "%ld", sortedModels.count)
        }else{
            self.totals = String(format: "0%ld", sortedModels.count)
        }
        self.dataSource = sortedModels
        onSuccess?(self.dataSource)
    }
}

@objcMembers
class SFPMaternityNotesModel: SFPModel,Codable {
    var feel = ""
    var date = ""
    var temperature = ""
    var quicken = ""
    var isDefault = true
    override class func getTableName() -> String {
        return  String(describing: SFPMaternityNotesModel.self)
    }
}
